package com.mezz.bones.framework.mybatis.dynamic.config;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.mezz.bones.framework.mybatis.dynamic.logging.DataSourceAwareStdOutImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author mezz
 * @date 2022-04-17 12:27
 * @description:
 */
@Configuration
@MapperScan("com.mezz.bones.**.mapper")
public class MybatisPlusLogConfig {


    @Value("${spring.profiles.active:default}")
    private String activeProfile;

    @Bean
    public ConfigurationCustomizer mybatisPlusConfigurationCustomizer() {

        //配置日志sql打印
        return configuration -> {
            if ("prod".equals(activeProfile)) {
                //生产环境关闭sql打印日志信息
                configuration.setLogImpl(org.apache.ibatis.logging.nologging.NoLoggingImpl.class);
            } else {
                configuration.setLogImpl(DataSourceAwareStdOutImpl.class);
            }
        };
    }

}
